<?php
namespace app\index\controller;

use think\Request;
use \app\admin\model\Soft as SoftModel;

class Soft extends Base
{
    protected $model;
    
    public function __construct(Request $request = null)
    {
        parent::__construct($request);

        $this->model = new SoftModel();
    }

    public function index($id)
    {
        // 正文
        $data = $this->model->find($id);

        $data->clicks +=1;
        
        @$data->save();

        // banner图
        $banner = $this->category_model->where('id', $data->cid)->value('banner');

        $data->banner = $banner;

        $this->assign('data', $data);
        return $this->fetch();
    }

    public function lists($cid = 31)
    {
        // 后面就变了,先输出当前cid
        $this->assign('cid', $cid);

        // banner,img_title图
        $data_banner =  $this->category_model->where('id', $cid)->field('banner, img_title')->find();
        
        if ($cid == 31) {
            $cid = $this->category_model->where('pid', $cid)->column('id');
        }
        $data = $this->model->field('id,title,thumb,summary')
            ->where('cid', 'in', $cid)
            ->where('status', 1)
            ->order('top')
            ->paginate(6);

        // echo json_encode($data);
        // exit;
        $this->assign('data', $data);
        $this->assign('data_banner', $data_banner);
        return $this->fetch();
    }
}
